package roborally;

import be.kuleuven.cs.som.annotate.Basic;

/**
 * An enum WeightUnit, that holds all possible types of weightunits(GRAM, KILOGRAM).
 * 
 * @version  2.90
 * @author   Michiel Ruelens & Dieter Naten
 */
public enum WeightUnit {
	GRAM("g"), KILOGRAM("kg");				//Units for weight
	
	private final String symbol;
	
	/**
	 * This method makes a new weightunit with the given symbol
	 * 
	 * @param symbol
	 * 		  The symbol the new weightunit should be given
	 * @post  | (new this).getSymbol() == symbol
	 */
	private WeightUnit(String symbol){
		this.symbol = symbol;
	}
	
	/**
	 * This method returns the current symbol.
	 */
	@Basic
	public String getSymbol() {
		return this.symbol;
	}
	
	/**
	 * Returns the value of another weightunit compared to 1 of this weightunit.
	 * 
	 * @param 	other
	 * 			The other weightunit that is compared to this one.
	 * @return	| result ==
	 * 			| getUnitFactor(this, other)
	 */
	public double toWeightUnitFactor(WeightUnit other){
		double factor = getWeightUnitFactor(this, other);
		return factor;	
	}
	
	/**
	 * Get the conversion rate between 2 weightunits. The result is the value of the second weightunit compared to 1 of the first weightunit.
	 * 
	 * @param 	unit1
	 * 			The weightunit to get the conversion rate with unit2.
	 * @param 	unit2
	 * 			The weightunit to get the conversion rate with unit1.
	 * @return  The conversion rate between the two given units.
	 * 			| result == 
	 * 			| factor
	 */
	public static double getWeightUnitFactor(WeightUnit unit1, WeightUnit unit2){
		double factor = 0;
		if(unit1==unit2){
			factor = 1;
		}
		else if(unit1==WeightUnit.GRAM && unit2==WeightUnit.KILOGRAM){
			factor = 1/1000;
		}
		else if(unit1==WeightUnit.KILOGRAM && unit2==WeightUnit.GRAM){
			factor = 1000;
		}
		return factor;
	}
	
//	/**
//	 * Returns true if the 2 units are compareable units.
//	 * Compareable units are:
//	 * 							- GRAM and KILOGRAM
//	 * 							- WATTSECOND and KILOWATTHOUR
//	 * @param unit1
//	 * 		  The first unit you want to check for compareability
//	 * @param unit2
//	 * 		  The second unit you want to check for compareability
//	 * @return | result==
//	 * 		   | (unit1==Unit.GRAM || unit1==Unit.KILOGRAM) && ( unit2==Unit.GRAM || unit2==Unit.KILOGRAM)
//	 * 		   | OR
//	 * 		   | (unit1==Unit.WATTSECOND || unit1==Unit.KILOWATTHOUR) && ( unit2==Unit.WATTSECOND || unit2==Unit.KILOWATTHOUR )
//	 */
//	public static boolean areCompareable(WeightUnit unit1, Unit unit2){
//		boolean result = false;
//		if((unit1==Unit.GRAM || unit1==Unit.KILOGRAM) && ( unit2==Unit.GRAM || unit2==Unit.KILOGRAM )){
//			result = true;
//		}
//		else if((unit1==Unit.WATTSECOND || unit1==Unit.KILOWATTHOUR) && ( unit2==Unit.WATTSECOND || unit2==Unit.KILOWATTHOUR )){
//			result = true;
//		}
//		return result;
//	}
}
